<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="Dashboard">
    <meta name="keyword" content="Dashboard, Bootstrap, Admin, Template, Theme, Responsive, Fluid, Retina">

    <title>辅导员管理</title>
    <!-- Bootstrap core CSS -->
    <link rel="shortcut icon" href="newtemplatesfiles5/img/favicon.html">
    <link href="newtemplatesfiles5/css/bootstrap.min.css" rel="stylesheet">
    <link href="newtemplatesfiles5/css/bootstrap-reset.css" rel="stylesheet">
    <!--external css-->
    <link href="newtemplatesfiles5/assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
    <link href="newtemplatesfiles5/assets/jquery-easy-pie-chart/jquery.easy-pie-chart.css" rel="stylesheet" type="text/css" media="screen"/>
    <link rel="stylesheet" href="newtemplatesfiles5/css/owl.carousel.css" type="text/css">
    <!-- Custom styles for this template -->
    <link href="newtemplatesfiles5/css/style.css" rel="stylesheet">
    <link href="newtemplatesfiles5/css/style-responsive.css" rel="stylesheet" />

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media queries -->
    <!--[if lt IE 9]>
    <script src="newtemplatesfiles5/js/html5shiv.js"></script>
    <script src="newtemplatesfiles5/js/respond.min.js"></script>
    <![endif]-->

</head>

<body>

<section id="container" >
    <!--header start-->
    <div th:insert="common/admin-common-header::top"></div>
    <!--header end-->
    <!--sidebar start-->
    <div th:insert="common/admin-common-sidebar::#left"></div>
    <!--sidebar end-->
    <section id="main-content">
        <section class="wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <!--div class="panel">
                        <header class="panel-heading">
                            通过文件批量导入 /////待实现
                        </header>
                        <div class="panel-body">
                            <a>仅支持.xls .xlsx格式</a><br>
                            <form role="form" id="fileForm">
                                <input type="file" name="file" accept=".xls,.xlsx">
                            </form><br>
                            <button type="submit" class="btn btn-info" onclick="addFlieStudent()">批量添加</button>
                        </div>
                    </div-->
                    <div class="panel">
                        <header class="panel-heading">
                            添加单个辅导员
                        </header>
                        <div class="panel-body">
                            <form role="form" id="myForm">
                                <div class="form-group">
                                    <label >学院</label>
                                    <select id="selectDepartment" name="departmentID" type="text" class="form-control" placeholder="学院">
                                        <option value="none" selected disabled hidden>请选择</option>
                                        <tr th:each="emp:${session.departmentList}">
                                            <option  th:value="${emp.departmentID}" th:text="${emp.departmentName}">
                                            </option>
                                        </tr>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>专业</label>
                                    <select id="major" name="majorID" type="text" class="form-control" placeholder="专业">
                                        <option value="none" selected disabled hidden>请选择</option>
                                        <option></option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>姓名</label>
                                    <input name="name" type="text" class="form-control" placeholder="">
                                </div>
                                <div class="form-group">
                                    <label>工号</label>
                                    <input name="schoolCounsellorID" type="text" class="form-control" placeholder="">
                                </div>
                                <div class="form-group">
                                    <label>性别:</label>
                                    <div class="form-check form-check-inline">
                                        <input class="form-check-input" type="radio" name="gender" value="男" checked>
                                        <label class="form-check-label">男</label>
                                    </div>
                                    <div class="form-check form-check-inline">
                                        <input class="form-check‐input" type="radio" name="gender" value="女">
                                        <label class="form-check-label">女</label>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label>初始密码</label>
                                    <input name="password" type="text" class="form-control" placeholder="默认123"  >
                                </div>
                            </form>
                            <button type="submit" class="btn btn-info" onclick="addOneSchoolCounsellor()">添加</button>
                        </div>
                    </div><!-- /content-panel -->
                </div><!-- /col-lg-4 -->
            </div><!-- /row -->



        </section>
    </section><!-- /MAIN CONTENT -->

    <!--main content end-->
</section>
<!-- js placed at the end of the document so the pages load faster -->
<script src="newtemplatesfiles5/js/jquery.js"></script>
<script src="newtemplatesfiles5/js/jquery-1.8.3.min.js"></script>
<script src="newtemplatesfiles5/js/bootstrap.min.js"></script>
<script src="newtemplatesfiles5/js/jquery.scrollTo.min.js"></script>
<script src="newtemplatesfiles5/js/jquery.nicescroll.js" type="text/javascript"></script>
<script src="newtemplatesfiles5/js/jquery.sparkline.js" type="text/javascript"></script>
<script src="newtemplatesfiles5/assets/jquery-easy-pie-chart/jquery.easy-pie-chart.js"></script>
<script src="newtemplatesfiles5/js/owl.carousel.js" ></script>
<script src="newtemplatesfiles5/js/jquery.customSelect.min.js" ></script>
<script src="newtemplatesfiles5/assets/jquery-knob/js/jquery.knob.js"></script>

<!--common script for all pages-->
<script src="newtemplatesfiles5/js/common-scripts.js"></script>


<script>

    function addFlieStudent(){
        var form = document.getElementById("fileForm");
        form = new FormData(form);
        $.ajax({
            url:"upLoadStudentFile.do",
            type:"post",
            dataType:"json",
            data:form,
            cache:false,
            processData:false,
            contentType:false,
            success: function (data) {
                console.log(data);

            },
            error:function (data) {
                console.log("error");
            }

        })
    };

    ////改变下拉框
    $("#selectDepartment").on("change",function(){
        var  departmentID = $("option:selected",this).val();
        form = new FormData();
        form.append("departmentID",departmentID);
        $.ajax({
            url:"getMajorList.do",
            type:"post",
            dataType:"json",
            data:form,
            cache:false,
            processData:false,
            contentType:false,
            success: function (data) {
                console.log(data);
                //console.log(data.length);
                var select = document.getElementById("major");
                select.options.length=0;
                for(var i = 0; i<data.length; i++){
                    //console.log(data[i].majorName);
                    select.options.add(new Option(data[i].majorName,data[i].majorID));
                }
            },
            error:function (data) {
                console.log("error");
            }

        })


    });

    function verifyLoginStatus() {
        //验证登录状态
        console.log("1");
        var message = document.getElementById("mystatus").innerText;
        console.log(message);
        if(message == '请先登录'){
            alert("请登录");
            location.href="login";
            return '1';
        }
        return '2';
    };

    function addOneSchoolCounsellor(){
        var status = verifyLoginStatus();
        if(status == '2'){
            var form = new FormData(document.getElementById("myForm"));
            $.ajax({
                url:"admin-addOneSchoolCounsellor.do",
                type:"post",
                dataType:"html",
                data:form,
                cache:false,
                processData:false,
                contentType:false,
                success: function (data) {
                    if(data=="success"){
                        alert("添加成功！");
                        location.href="admin-addSchoolCounsellor";
                    }else {
                        alert(data);
                    }
                },
                error:function (data) {
                    console.log("error");
                    alert("添加失败");
                }
            })
        }
    };

    $(".knob").knob();
</script>


</body>
</html>
